

private: System::Void AddImage_Click(System::Object *  sender, System::EventArgs *  e)
			 {
				 if(AddImageDlg->ShowDialog() == DialogResult::OK)
				 {
					 Image *pix = Image::FromFile(AddImageDlg->FileName);
					 ImageBox->Width = pix->Width;
					 ImageBox->Height = pix->Height;
					 ImageBox->Image = pix;

					 origW = pix->Width;
					 origH = pix->Height;

					 file->SetImageName(StringToArray(AddImageDlg->FileName));
					 pathName->Text = AddImageDlg->FileName;
					 needsSave(true);
				 }
			 }

private: System::Void ImageBox_MouseDown(System::Object *  sender, System::Windows::Forms::MouseEventArgs *  e)
		 {
			 AnimObject *curAni;

			 if(AniList->SelectedIndex >= 0)
				curAni = (AnimObject*)AniList->SelectedItem;
			 else
				 curAni = NULL;

			 if(e->Button == MouseButtons::Left && !ctrlDown)
			 {
				dragging = true;
				startX = e->X;
				startY = e->Y;

				selection.X = e->X;
				selection.Y = e->Y;
				selection.Width = 0;
				selection.Height = 0;

			 }
			 else if(e->Button == MouseButtons::Right)
			 {
				 if(!selection.Contains(e->X, e->Y))
					 return;

				 hotx = e->X - selection.X;
				 hoty = e->Y - selection.Y;

				 //if a frame is selected
				 if(FrameList->SelectedIndex >= 0 && curAni != NULL)
				 {
					FrameObject *newFrame = curAni->GetFrame(FrameList->SelectedIndex);
					newFrame->f->hotx = hotx / zoomLevel;
					newFrame->f->hoty = hoty / zoomLevel;
				 }

				 ImageBox->Invalidate();
				 needsSave(true);
			 }

			 if(e->Button == MouseButtons::Left && ctrlDown)
			 {
				 if(!selection.Contains(e->X, e->Y))
					 return;

				 if(curAni != NULL)
				 {
					TGNAni *temp = curAni->GetAni();

					bounds.X = e->X;
					bounds.Y = e->Y;
					bounds.Width = temp->boundW * zoomLevel;
					bounds.Height = temp->boundH * zoomLevel;

					//if they have a frame selected...
					if(FrameList->SelectedIndex >= 0)
					{
						FrameObject *newFrame = curAni->GetFrame(FrameList->SelectedIndex);
						newFrame->f->boundx = (bounds.X - selection.X) / zoomLevel;
						newFrame->f->boundy = (bounds.Y - selection.Y) / zoomLevel;
					}
				 }

				 ImageBox->Invalidate();
				 needsSave(true);
			 }
		 }

private: System::Void ImageBox_MouseMove(System::Object *  sender, System::Windows::Forms::MouseEventArgs *  e)
		 {
			 if(dragging)
			 {
				 ImageBox->Refresh();
				
				 if (e->X >= selection.X)  
					selection.Width = e->X - startX;

				 if (e->Y >= selection.Y)    
					selection.Height = e->Y - startY;

				 selectionMade = true;

				 ImageBox->Invalidate();
			 }
		 }

private: System::Void ImageBox_Paint(System::Object *  sender, System::Windows::Forms::PaintEventArgs *  e)
		 {
			 if(ImageBox->Image && (selectionMade || selection.X > 0))
			 {
				 Pen* pen = new Pen(Brushes::Red, zoomLevel);
				 Pen* hotPen = new Pen(Brushes::Blue, zoomLevel);
				 Pen* boundsPen = new Pen(Brushes::GreenYellow, zoomLevel);
				 Pen* midPen = new Pen(Brushes::Cyan, zoomLevel);

				 pen->DashStyle = System::Drawing::Drawing2D::DashStyle::Dash;
				 boundsPen->DashStyle = System::Drawing::Drawing2D::DashStyle::Dash;
				 
				 Graphics* g = e->Graphics;
				 //g->DrawRectangle(pen, selection.X * zoomLevel, selection.Y * zoomLevel, selection.Width * zoomLevel, selection.Height * zoomLevel);
				 g->DrawRectangle(pen, selection.X, selection.Y, selection.Width, selection.Height);

				 if(bounds.X > 0)
					 g->DrawRectangle(boundsPen, bounds.X, bounds.Y, bounds.Width, bounds.Height);
					//g->DrawRectangle(boundsPen, selection.X * zoomLevel, bounds.Y * zoomLevel, bounds.Width * zoomLevel, bounds.Height * zoomLevel);

				 int newx, newy;
				 newx = hotx + selection.X;
				 newy = hoty + selection.Y;

				 g->DrawLine(midPen, bounds.X + (bounds.Width / 2), bounds.Y, bounds.X + (bounds.Width / 2), bounds.Y + bounds.Height);
				 //hot spot
				 g->DrawLine(hotPen, newx - 5, newy, newx + 5, newy);
				 g->DrawLine(hotPen, newx, newy - 5, newx, newy + 5);
			 }
		 }

private: System::Void ImageBox_MouseUp(System::Object *  sender, System::Windows::Forms::MouseEventArgs *  e)
		 {
			 dragging = false;
			 AddFrame->Enabled = true;
		 }


private: System::Void ZoomIn_Click(System::Object *  sender, System::EventArgs *  e)
		 {
			 if(!ImageBox->Image || origW == 0 || origH == 0 || zoomLevel == 5)
				 return;

			 int oldIndex = FrameList->SelectedIndex;
			 FrameList->SelectedIndex = -1;

			 //put everything back to it's regular size
			 selection.X /= zoomLevel;
			 selection.Y /= zoomLevel;
			 selection.Width /= zoomLevel;
			 selection.Height /= zoomLevel;
 
		 	 hotx /= zoomLevel;
		     hoty /= zoomLevel;

			 bounds.X /= zoomLevel;
			 bounds.Y /= zoomLevel;
			 bounds.Width /= zoomLevel;
			 bounds.Height /= zoomLevel;

			 //increase the zoom level after putting things at 100%
			 zoomLevel++;

			 //then make everything bigger
			 ImageBox->Width = origW * zoomLevel;
			 ImageBox->Height = origH * zoomLevel;

			 selection.X *= zoomLevel;
			 selection.Y *= zoomLevel;
			 selection.Width *= zoomLevel;
			 selection.Height *= zoomLevel;
 
		 	 hotx *= zoomLevel;
		     hoty *= zoomLevel;

			 bounds.X *= zoomLevel;
			 bounds.Y *= zoomLevel;
			 bounds.Width *= zoomLevel;
			 bounds.Height *= zoomLevel;

			 FrameList->SelectedIndex = oldIndex;
			 ImageBox->Refresh();
		 }

private: System::Void ZoomOut_Click(System::Object *  sender, System::EventArgs *  e)
		 {
			 if(!ImageBox->Image || origW == 0 || origH == 0 || zoomLevel == 1)
				 return;

			 int oldIndex = FrameList->SelectedIndex;
			 FrameList->SelectedIndex = -1;

			 selection.X /= zoomLevel;
			 selection.Y /= zoomLevel;
			 selection.Width /= zoomLevel;
			 selection.Height /= zoomLevel;
 
		 	 hotx /= zoomLevel;
		     hoty /= zoomLevel;

			 bounds.X /= zoomLevel;
			 bounds.Y /= zoomLevel;
			 bounds.Width /= zoomLevel;
			 bounds.Height /= zoomLevel;

			 zoomLevel--;

			 ImageBox->Width = origW * zoomLevel;
			 ImageBox->Height = origH * zoomLevel;

			 selection.X *= zoomLevel;
			 selection.Y *= zoomLevel;
			 selection.Width *= zoomLevel;
			 selection.Height *= zoomLevel;
 
		 	 hotx *= zoomLevel;
		     hoty *= zoomLevel;

			 bounds.X *= zoomLevel;
			 bounds.Y *= zoomLevel;
			 bounds.Width *= zoomLevel;
			 bounds.Height *= zoomLevel;

			 FrameList->SelectedIndex = oldIndex;
			 ImageBox->Refresh();

		 }

private: System::Void updatePathName_Click(System::Object *  sender, System::EventArgs *  e)
		 {
			 file->SetImageName(StringToArray(pathName->Text));
			 needsSave(true);
			 
		 }